package business

import (
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
    model "ruoyi-go/app/admin/model/business"
    "ruoyi-go/app/admin/model/tools"
    "ruoyi-go/utils/R"
    "strconv"
)

func CreateC5SiteInfo(context *gin.Context) {
	userId, _ := context.Get("userId")
	log.Println(userId)
	var req model.C5SiteInfo
    if err := context.ShouldBindJSON(&req);err != nil {
		context.JSON(http.StatusOK, R.ReturnFailMsg("获取参数失败"))
	} else {
		res := model.CreateC5SiteInfoService(req)
		context.JSON(http.StatusOK, res)
	}
}

func DeleteC5SiteInfo(context *gin.Context) {
	var id = context.Param("id")
    result := model.DeleteC5SiteInfoService(id)
    context.JSON(http.StatusOK, result)
}

func DeleteC5SiteInfoByIds(context *gin.Context) {
    var ids = context.Param("ids")
    result := model.DeleteC5SiteInfoByIdsService(ids)
    context.JSON(http.StatusOK, result)
}

func UpdateC5SiteInfo(context *gin.Context) {
    var req model.C5SiteInfo
    if err := context.ShouldBindJSON(&req);err != nil {
		context.JSON(http.StatusOK, R.ReturnFailMsg("获取参数失败"))
	} else {
		res := model.UpdateC5SiteInfoService(req)
		context.JSON(http.StatusOK, res)
	}
}

func GetC5SiteInfo(context *gin.Context) {
    idstr:=context.Param("id")    //查询路径Path参数
    id, err := strconv.ParseInt(idstr, 10, 64)
    if err!=nil{
        context.JSON(http.StatusOK, R.ReturnFailMsg("获取参数失败"))
    }else{
        res := model.GetC5SiteInfoService(id)
    	context.JSON(http.StatusOK, res)
    }
}

func GetPageLimitC5SiteInfo(context *gin.Context) {
    pageNum, _ := strconv.Atoi(context.DefaultQuery("pageNum", "1"))
    pageSize, _ := strconv.Atoi(context.DefaultQuery("pageSize", "10"))

    beginTime := context.DefaultQuery("params[beginTime]", "")
    endTime := context.DefaultQuery("params[endTime]", "")

    var param = tools.SearchTableDataParam{
        PageNum:  pageNum,
        PageSize: pageSize,
        Other: model.C5SiteInfo{
        },
        Params: tools.Params{
            BeginTime: beginTime,
            EndTime:   endTime,
        },
    }

    result := model.GetPageLimitC5SiteInfoService(param)
    context.JSON(http.StatusOK, result)
}
